package net.wanho.util;

import lombok.Data;

/**
 * Ajax响应结果对象
 */
@Data
public class AjaxResult {
    // 状态码
    private Integer status;
    // 消息
    private String msg;
    // 数据
    private Object data;

    /**
     * 返回一个表示成功的AjaxResult
     * @return
     */
    public static AjaxResult success(String msg){
        AjaxResult result = new AjaxResult();
        result.setStatus(200);
        result.setMsg(msg);
        return result;
    }

    public static AjaxResult success(Object data){
        AjaxResult result = new AjaxResult();
        result.setStatus(200);
        result.setMsg("success");
        result.setData(data);
        return result;
    }

    public static AjaxResult error(String msg){
        AjaxResult result = new AjaxResult();
        result.setStatus(500);
        result.setMsg(msg);
        return result;
    }
}
